package com.wandousoushu.jiusen.ui.widget.image;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;

import com.wandousoushu.jiusen.MyApplication;
import com.wandousoushu.jiusen.R;

import org.jetbrains.annotations.Nullable;

@SuppressLint("AppCompatCustomView")
public class VipImageView extends ImageView {
    private boolean isVip = false;
    private static Bitmap vipbmp = null;
    private static Paint paint;

    static {
        vipbmp = BitmapFactory.decodeResource(MyApplication.getInstance().getResources(), R.drawable.vip_mine);

        paint = new Paint();
        paint.setColor(MyApplication.getInstance().getResources().getColor(R.color.transparent));
        paint.setStyle(Paint.Style.FILL);
    }

    public VipImageView(Context context) {
        super(context);
    }

    public VipImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public VipImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public VipImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void isVip(boolean isVip) {
        this.isVip = isVip;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (isVip) {
            //canvas.drawRect(canvas.getWidth() - vipbmp.getWidth() - 18, canvas.getHeight() - vipbmp.getHeight(), canvas.getWidth(), canvas.getHeight(), paint);
            canvas.drawBitmap(vipbmp, canvas.getWidth() - vipbmp.getWidth() - 9, canvas.getHeight() - vipbmp.getHeight(), null);
        }
    }
}
